<?php
require('common_view_functions.php');
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Blog 用户后台管理 - 关注及评论</title>
<link rel="shortcut icon" href="/img/favicon.ico" />
<link rel="stylesheet" type="text/css" href="/css/mgmt.css" />
<link rel="stylesheet" type="text/css" href="/css/3rd/jqModal.css" />
</head>
<body id="bodyComments">
<div id="wrapper">
	<!-- header -->
	<?php require('common_header.php'); ?>
	<!-- /header -->
	<div id="body">
		<div id="bigger_main">
			<div id="my_watches">
				<fieldset>
					<legend>我关注的网志</legend>
					<div id="myWatchListDiv">Loading...</div>
				</fieldset>
			</div>
			<div id="for_comments">
				<fieldset>
					<legend>待审核评论</legend>
					<dl id="unauthedCommentsDl" class="mgmtComments">
						<dd>Loading...</dd>
					</dl>
					<div style="text-align:right;padding-top:2px;font-size:90%;">
						将选中的评论：
						<input type="button" id="btnAuthComments" class="button" value="通过审核" />
						<input type="button" id="btnDeleteComments" class="button" value="删除" />
					</div>
				</fieldset>
				<fieldset>
					<legend>最近评论</legend>
					<dl id="newCommentsDl" class="mgmtComments">
						<dd>Loading...</dd>
					</dl>
				</fieldset>
			</div>
			<div class="z"></div>
		</div>
		<div class="z"></div>
	</div>
	<!-- footer -->
	<?php require('common_footer.php'); ?>
	<!-- /footer -->
</div>

<!-- JS -->
<script type="text/javascript" src="/js/3rd/jquery.pack.js"></script>
<script type="text/javascript" src="/js/3rd/jqModal.js"></script>
<script type="text/javascript" src="/js/3rd/json2.js"></script>
<script type="text/javascript">
<!--
var g_userSiteRoot = "<?php echo('/' . $blogger_uri); ?>";
var loadWatchListFinished = false;
var loadUnauthedCommentsFinished = false;

function getCheckedItems() {
	var ids = $("#unauthedCommentsDl input:checked");
	var idsarr = [];
	if(ids.length > 0) {
		for(var i = 0; i < ids.length; i++) {
			idsarr.push(ids[i].value);
		}
	}
	return idsarr;
}

function deleteSubscriptionCallback(rdata) {
	$("#ajaxLoading").hide();
	
	rdata = rdata.split("_");
	if(rdata[0] != "SUCC") {
		alert("Operation failed!");
		return;
	}
	
	loadWatchList();
}

function loadWatchListCallback() {
//	$("#ajaxLoading").hide();
	loadWatchListFinished = true;
	
	$("#myWatchListDiv table td.oper a").click(function() {
		var oid = $(this).attr("rel");
		oid = oid.split("_");
		if(confirm("确定要删除这条关注？")) {
			$("#ajaxLoading").show();
			$.post(g_userSiteRoot + "/mgmt/comments", {
				"hidIsPostBack": "ja",
				"operation": "delete_subscription",
				"entry_id": oid[1]
			}, deleteSubscriptionCallback);
		}
	});
}

function loadWatchList() {
//	$("#ajaxLoading").show();
	$("#myWatchListDiv").load(g_userSiteRoot + "/mgmt/watches_list", {
		"R": Math.random()
	}, loadWatchListCallback);
}

function loadUnauthedCommentsCallback() {
//	$("#ajaxLoading").hide();
	loadUnauthedCommentsFinished = true;
}

function loadUnauthedComments() {
//	$("#ajaxLoading").show();
	$("#unauthedCommentsDl").load(g_userSiteRoot + "/mgmt/comments_list/0", {
		"R": Math.random()
	}, loadUnauthedCommentsCallback);
}

function loadRecentCommentsCallback() {
	$("#ajaxLoading").hide();
}

function loadRecentComments() {
//	$("#ajaxLoading").show();
	$("#newCommentsDl").load(g_userSiteRoot + "/mgmt/comments_list/1", {
		"R": Math.random()
	}, loadRecentCommentsCallback);
}

function authCommentsCallback(rdata) {
	$("#ajaxLoading").hide();
	
	rdata = rdata.split("_");
	if(rdata[0] != "SUCC") {
		alert("Operation failed!");
		return;
	}
	
	loadUnauthedComments();
}

function deleteCommentsCallback(rdata) {
	$("#ajaxLoading").hide();
	
	rdata = rdata.split("_");
	if(rdata[0] != "SUCC") {
		alert("Operation failed!");
		return;
	}
	
	loadUnauthedComments();
}

$(document).ready(function() {
	$("#btnAuthComments").click(function() {
		if(loadUnauthedCommentsFinished) {
			var arrIds = getCheckedItems();
			if(arrIds.length == 0) {
				alert("没有选中任何项目。");
				return;
			}
			if(confirm("确定要将所选的评论通过审核？")) {
				$("#ajaxLoading").show();
				$.post(g_userSiteRoot + "/mgmt/comments", {
					"hidIsPostBack": "ja",
					"operation": "auth_comments",
					"posted_data": JSON.stringify(arrIds)
				}, authCommentsCallback)
			}
		}
	});
	
	$("#btnDeleteComments").click(function() {
		if(loadUnauthedCommentsFinished) {
			var arrIds = getCheckedItems();
			if(arrIds.length == 0) {
				alert("没有选中任何项目。");
				return;
			}
			if(confirm("确定要删除所选的评论？")) {
				$("#ajaxLoading").show();
				$.post(g_userSiteRoot + "/mgmt/comments", {
					"hidIsPostBack": "ja",
					"operation": "delete_comments",
					"posted_data": JSON.stringify(arrIds)
				}, deleteCommentsCallback);
			}
		}
	});
	
	$("#ajaxLoading").show();
	loadWatchList();
	loadUnauthedComments();
	loadRecentComments();
});
// -->
</script>
<!-- /JS -->

<div id="ajaxLoading"><img alt="Loading..." src="<?php echo('/' . 'img/ajax_loading.gif'); ?>" border="0" width="24" height="24" /></div>
</body>
</html>